package com.jijuxie.common.utils;

import cn.hutool.crypto.digest.BCrypt;
import com.jijuxie.common.exception.ServiceException;

public class SecurityUtils {

    /**
     * 加密密码
     */
    public static String encryptPassword(String password) {
        return BCrypt.hashpw(password);
    }

    /**
     * 验证密码是否正确
     */
    public static boolean matchesPassword(String rawPassword, String encodedPassword) {
        return BCrypt.checkpw(rawPassword, encodedPassword);
    }

    /**
     * 验证密码长度
     */
    public static void validatePassword(String password) {
        if (password == null || password.length() < 6 || password.length() > 20) {
            throw new ServiceException("密码长度必须在6到20个字符之间");
        }
    }
}
